package com.atguigu.gmall.item.all.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.client.ItemFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

/**
 * @author atguigu-mqx
 */
@Controller
public class ItemController {

    @Autowired
    private ItemFeignClient itemFeignClient;
    //  https://item.jd.com/100016034400.html
    //  http://item.gmall.com/17.html
    //  编写控制器
    @RequestMapping("{skuId}.html")
    public String getItem(@PathVariable Long skuId, Model model){
        //  获取数据
        Result<Map> result = itemFeignClient.getItem(skuId);
        //  存储数据
        model.addAllAttributes(result.getData());
        //  返回的视图名称
        return "item/item";
    }
}
